package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.mapper.ChangeUserImportMapper;
import com.koron.css2.clientCenter.queryBean.ChangeUserImportQueryBean;
import com.koron.css2.clientCenter.vo.ChangeUserImportVo;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class ChangeUserImportList implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		// TODO Auto-generated method stub
		ChangeUserImportQueryBean queryBean = JsonUtils.objectToPojo(req.getData(), ChangeUserImportQueryBean.class);
		
		try {
			ChangeUserImportMapper mapper = factory.getMapper(ChangeUserImportMapper.class);
			PageHelper.startPage(queryBean.getPage(), queryBean.getPageCount());
			List<ChangeUserImportVo> list = mapper.selectList(queryBean);
			for (ChangeUserImportVo vo : list) {
				vo.setProcessName(vo.getProcessName()==null?"草稿":vo.getProcessName());
			}
			@SuppressWarnings("rawtypes")
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", PageInfo.class);
			info.setData(new PageInfo<>(list));
			return info;
		} catch (Exception e) {
			logger.error("批量变更列表查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
